package com.test.CallableDemo;

import org.junit.Test;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * ${DESCRIPTION}
 *
 * @author muxiaoyu
 * @create 2017/06/07 16:43
 **/
public class CallableImpl implements Callable {
    private volatile static Integer i = 0;

    @Override
    public Integer call() throws Exception {
        while (i < 1000) {
            synchronized (new Object()) {
                System.out.println(Thread.currentThread().getName() + "==========" + i);
                i++;
            }
        }
        return i;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask ft = new FutureTask(new CallableImpl());
        Thread thread2 = new Thread(ft);
        Thread thread3 = new Thread(new FutureTask(new CallableImpl()));
        Thread thread4 = new Thread(new FutureTask(new CallableImpl()));
        thread2.start();
        thread3.start();
        thread4.start();
        System.out.println(ft.get());
    }

    @Test
    public void test111() {
        Integer i1 = 3;
        Integer i2 = 3;
        System.out.println(i1 == i2);
    }
}
